package com.yinian.server.controller;


import com.yinian.common.constant.JwtClaimsConstant;
import com.yinian.common.constant.MessageConstant;
import com.yinian.common.properties.JwtProperties;
import com.yinian.common.result.Result;
import com.yinian.common.utils.JwtUtil;
import com.yinian.common.utils.MailService;
import com.yinian.pojo.dto.CommunityInsertDTO;
import com.yinian.pojo.dto.UserLoginDTO;
import com.yinian.pojo.dto.UserRegisterDTO;
import com.yinian.pojo.dto.VerificationCodeDTO;
import com.yinian.pojo.entity.Community;
import com.yinian.pojo.entity.User;
import com.yinian.pojo.vo.CommunityVO;
import com.yinian.pojo.vo.UserLoginVO;
import com.yinian.pojo.vo.UserRegisterVO;
import com.yinian.server.service.CommunityService;
import com.yinian.server.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;


/**
 *  社区论坛
 *
 *  */
@RestController
@Slf4j
@Api(tags = "社区论坛相关接口")
public class CommunityController {

    @Autowired
    private CommunityService communityService;


    /**
     * 社区论坛
     *
     *
     * @return
     */
    @GetMapping("/community")
    @ApiOperation(value = "社区论坛")
    public Result<List<CommunityVO>> GetCommunity() {
        log.info("社区论坛");
        log.info(communityService.getCommunity().toString());
        return Result.success(communityService.getCommunity());
    }

    @PostMapping ("community-insert")
    @ApiOperation(value = "社区论坛")
    public Result InsertMessage(@RequestBody CommunityInsertDTO communityInsert) {
        log.info("新增留言");
        long userId = communityInsert.getUserId();
        String content = communityInsert.getContent();
        communityService.insertMessage(userId,content);
        return Result.success();
    }
}
